package com.example.myapplication.adapter;

import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.myapplication.R;
import com.example.myapplication.data.ThemeData;
import com.example.myapplication.utils.OkHttpTool;

import java.util.List;

public class Theme extends RecyclerView.Adapter<Theme.My> {
    private List<ThemeData.RowsDTO> list;
    private Context context;
    private View view;

    public Theme(List<ThemeData.RowsDTO> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @NonNull
    @Override
    public My onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view = LayoutInflater.from(context).inflate(R.layout.theme,null);
        return new My(view);
    }

    @Override
    public void onBindViewHolder(@NonNull My holder, int position) {
        Glide.with(context).load(OkHttpTool.URL + list.get(position).getCover()).into(holder.imags);
        String str = list.get(position).getTitle().substring(0, 10);
        holder.text.setText(str+"...");
    }

    @Override
    public int getItemCount() {
        return list != null?2:0;
    }

    public class My extends RecyclerView.ViewHolder{
        private ImageView imags;
        private TextView text;
        public My(@NonNull View itemView) {
            super(itemView);
            imags = view.findViewById(R.id.imags);
            text = view.findViewById(R.id.text);
        }
    }
}
